package com.larry.spark.rdd.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

object RDD_Oper_PartitionBy {

  def main(args: Array[String]): Unit = {
    //TODO  使用spark 重分区 partitionBy

    val conf = new SparkConf().setMaster("local[*]").setAppName("rdd")
    val sc = new SparkContext(conf)

    val rdd: RDD[Int] = sc.makeRDD(List(1,2,3,4),2)
    //根据指定规则对每一条数据进行重分区

    val rdd1 = rdd.map((_, 1))

    rdd1.partitionBy(new HashPartitioner(2)).saveAsTextFile("out4")

    sc.stop()
  }
}
